package cn.xuguowen.user.designPatten.chain_of_responsibility.article.common;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName: Client
 * Package: cn.xuguowen.user.designPatten.chain_of_responsibility.article.common
 * Description: 客户端
 *
 * @Author 徐国文
 * @Create 2023/6/3 9:06
 * @Version 1.0
 */
public class Client {
    private List<ArticleFilterEnum> articleFilterEnumList;

    private List<ArticleFilter> articleFilterList;

    private void init() {
        this.articleFilterList = ArticleFilterFactory.createArticleFilter(articleFilterEnumList);
    }

    public void doFilter(List<Article> articleList) {
        articleList.stream().filter(x -> {
            ArticleContext articleContext = new ArticleContext();
            articleContext.setArticle(x);
            return doFilter(articleContext);
        }).collect(Collectors.toList());

    }

    public boolean doFilter(ArticleContext articleContext) {
        for (ArticleFilter articleFilter : articleFilterList) {
            if (articleFilter.doFilter(articleContext)) {
                return false;
            }
        }
        return true;
    }
}
